
import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import util.MyConnection;

import java.sql.DriverManager;
import java.sql.Statement;
import java.text.DateFormat;
import java.util.*;

public class create extends HttpServlet {
	String fname = null;
	String email1 = null;
	int k = 0;

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		res.setContentType("text/html");
		int state = 0;

		PrintWriter out = res.getWriter();
		// System.out.println("inside");

		fname = req.getParameter("fname");
		String lname = req.getParameter("lname");
		email1 = req.getParameter("email");
		String remail1 = req.getParameter("remail");
		String dob = req.getParameter("dob");
		String gender = req.getParameter("gender");
		String aggree = req.getParameter("agree");
		String city = req.getParameter("city");
		String iam = req.getParameter("iam");
		String working = req.getParameter("working");
		// String pass=req.getParameter("pass");

		if (fname != null || lname != null || email1 != null || remail1 != null
				|| dob != null || gender != null || aggree != null
				|| city != null || iam != null || working != null) {

			try {
				DateFormat formatter = null;
				Date dat;
				String sss;
				int rs1;

				System.out
						.println("Print Value : ### : " + fname + " : " + lname != null
								+ " : "
								+ email1
								+ " : "
								+ remail1
								+ " : "
								+ dob
								+ " : "
								+ gender
								+ " : "
								+ aggree
								+ " : "
								+ city + " : " + iam + " : " + working);

				Statement s = MyConnection.getStatement();

				rs1 = s.executeUpdate("insert into register(fname,lname,email,dob,gender,agree,city,iam,working) values('"
						+ fname
						+ "','"
						+ lname
						+ "','"
						+ email1
						+ "','"
						+ dob
						+ "','"
						+ gender
						+ "','"
						+ aggree
						+ "','"
						+ city
						+ "','" + iam + "','" + working + "')");

				if (email1 != null) {
					if (rs1 == 1) {
						// if(k==0){
						call();
						// }
						res.sendRedirect("mailsend1.jsp?emailid=" + email1
								+ "&usern=" + fname);

					} else {
						res.sendRedirect("register.jsp?createstaf=fail");
					}
				}
			} catch (Exception e1) {

				e1.printStackTrace();
			}

		}

	}

	private void call() {
		// TODO Auto-generated method stub
		int upload = 0, download = 0;

		try {

			String active = "yes";
			int rs1;
			Statement s = MyConnection.getStatement();

			rs1 = s.executeUpdate("insert into rating(sname,sid,upload,download) values('"
					+ fname
					+ "','"
					+ email1
					+ "','"
					+ upload
					+ "','"
					+ download + "')");

			if (rs1 == 1) {
				System.out.println("works");
				// k=1;
				// res.sendRedirect("register.jsp?createstas=success");

			} else {
				// res.sendRedirect("register.jsp?createstaf=fail");
			}

		} catch (Exception e1) {

			e1.printStackTrace();
		}

	}
}
